capture log close
cd "C:\Research\Legal Services Corporation\"

log using "dose_response_results.txt", text replace

/*
foreach year in "08" "09" "10" "11" "12" "13" "14" "15" "16" "17" {
  use "acs_small20`year'.dta", clear

  recode mig (1=0) (2 3=1), gen(moved)

  gen rent=ten==3 if ten!=.

  gen treat=povpip<125 & rent if povpip!=.

  gen clustervar=povpip*10+rent

  rename st statefips

  levelsof statefips, local(vals)

  gen state_est=.
  gen state_pop=.
  gen state_se=.

  drop if cit==5 | mil==1

  foreach whichstate in `vals' {
    capture {
      reghdfe move treat if statefips==`whichstate' & (povpip>=75 & povpip<=175), absorb(rent povpip) cluster(clustervar)

      replace state_est=_b[treat] if statefips==`whichstate'
      replace state_se=_se[treat] if statefips==`whichstate'
    }
  
    sum statefips if statefips==`whichstate' [aweight=pwgtp]
    replace state_pop=r(sum_w) if statefips==`whichstate'
  }

  duplicates drop statefips, force

  gen year=20`year'
  keep statefips year state_est state_pop state_se
  save "estimates20`year'.dta", replace
}
*/

use estimates2008.dta, clear

forvalues year=2009(1)2017 {
  append using "estimates`year'.dta"
}

merge 1:1 statefips year using "lsc_caseloads.dta"

gen lsc_housing_rate=lsc_housing/state_pop*1000
gen lhousing=log(lsc_housing_rate)


reghdfe state_est lhousing, absorb(statefips year) cluster(statefips)
reghdfe state_est lhousing, absorb(statefips year) cluster(statefips year)

gen lfamily=log(lsc_family/state_pop*1000)

reghdfe state_est lfamily, absorb(statefips year) cluster(statefips year)
reghdfe state_est lhousing lfamily, absorb(statefips year) cluster(statefips year)


list state state_est lsc_housing_rate if year==2017, notrim noobs
reg state_est lsc_housing_rate if year==2017, robust

log close
